﻿'// ========================================================================= '
'// ------------------------------------------------------------------------- '
'//!				\file		CM_3DPoints.vb
'			        \date		june 2010
'			        \author		TNick
'
'			        \brief		
'
'
'   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'   This file is considered universal knowledge. No restrictions
'   are imposed; use as you see fit.
'   Please read ReadMe.txt and Licence.txt in root folder
'   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'
'   
'   Edit functionality is to be tested / debugged
'
'// ------------------------------------------------------------------------- '
'// ========================================================================= '
'//
'//
'//
'//
'//  IMPORTS     ------------------------------------------------------------ '

Imports System.Windows.Forms

'//  IMPORTS     ============================================================ '
'//
'//
'//
'//
'//  DEFINITIONS    --------------------------------------------------------- '


'//  DEFINITIONS    ========================================================= '
'//
'//
'//
'//
'//  DATA    ---------------------------------------------------------------- '


'//  DATA    ================================================================ '
'//
'//
'//
'//
'//  CLASS    --------------------------------------------------------------- '
Public Class CD_Mngr



    '// --------------------------------------------------------------------- '
    Private Sub OK_Button_Click( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles OK_Button.Click


        '// unload unchecked modules
        Dim cMIDS As MIDS
        For i As Integer = 0 to LS_ModLst.Items.Count - 1
            cMIDS = DirectCast(LS_ModLst.Items(i).Tag, MIDS)
            If LS_ModLst.Items(i).Checked = True Then
                '// should be loaded
                If (CApp.MLoadState(cMIDS) <> "") Then
                    '// already loaded
                    Continue For
                End if
                Select Case cMIDS
                    Case    MIDS.GRID:
                        CApp.mi_Grid = New CM_Grid()
                    Case    MIDS.FSK_PT3D:
                        CApp.mi_3DPoints = New CM_3DPoints()
                    Case    MIDS.DIMS:
                        CApp.mi_Dims = New CM_Dims()
                    Case    MIDS.IMGDB:
                        CApp.mi_ImageDb = New CM_ImageDb()
                    Case    MIDS.POLYA:
                        CApp.mi_PolyArea = New CM_PolyArea()
                    Case    MIDS.SIMB:
                        CApp.mi_Symbols = New CM_Symbols()
                    Case Else
                        Debug.Print("!! CD_Mngr->OK: missing type 1 !!" & vbNewLine)
                End Select
                CApp.MLoadState(cMIDS) = "1"c
            Else
                '// should be unloaded
                If (CApp.MLoadState(cMIDS) = "") Then
                    '// already unloaded
                    Continue For
                End if
                Select Case cMIDS
                    Case    MIDS.GRID:
                        CApp.mi_Grid.Terminate()
                        CApp.mi_Grid = Nothing
                    Case    MIDS.FSK_PT3D:
                        CApp.mi_3DPoints.Terminate()
                        CApp.mi_3DPoints = Nothing
                    Case    MIDS.DIMS:
                        CApp.mi_Dims.Terminate()
                        CApp.mi_Dims = Nothing
                    Case    MIDS.IMGDB:
                        CApp.mi_ImageDb.Terminate()
                        CApp.mi_ImageDb = Nothing
                    Case    MIDS.POLYA:
                        CApp.mi_PolyArea.Terminate()
                        CApp.mi_PolyArea = Nothing
                    Case    MIDS.SIMB:
                        CApp.mi_Symbols.Terminate()
                        CApp.mi_Symbols = Nothing
                    Case Else
                        Debug.Print("!! CD_Mngr->OK: missing type 2 !!" & vbNewLine)
                End Select
                CApp.MLoadState(cMIDS) = CChar("")
            End If
        Next



        CMain.eAppLang = DirectCast(Me.CB_Lang.SelectedIndex, CMain.ELANG)
        CMain.eAppDbg = DirectCast(Me.CB_Debug.SelectedIndex,CMain.EDEBUG)

        If Me.RB_A_Popup.Checked = true Then
            CMain.bAlertType = CMain.ALERTTY.MSGB
        Else
            CMain.bAlertType = CMain.ALERTTY.PROMPT
        End If
        If Me.RB_I_Popup.Checked = true Then
            CMain.bInformType = CMain.INFORMTY.MSGB
        Else
            CMain.bInformType = CMain.INFORMTY.PROMPT
        End If



        '// are we auto-runned?
        If (CK_AutoRun.Checked = False) Then
            CApp.regAppAddInKey.SetValue("LOADCTRLS", 16, Microsoft.Win32.RegistryValueKind.DWord)
        Else
            CApp.regAppAddInKey.SetValue("LOADCTRLS", 14, Microsoft.Win32.RegistryValueKind.DWord)
        End If

        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub Cancel_Button_Click( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles Cancel_Button.Click

        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub CD_Mngr_Load( _
        ByVal sender As System.Object,  _
        ByVal e As System.EventArgs) _
        Handles MyBase.Load


        Me.Text = "Field Survey Kit. " & CMain._T(TX.SETTINGS) & "."

        Me.OK_Button.Text = CMain._T(TX.OK)
        Me.Cancel_Button.Text = CMain._T(TX.CANCEL)

        Me.TP_GenStg.Text = CMain._T(TX.GENSTG)
        Me.TP_Modules.Text = CMain._T(TX.MODULES)

        Me.LS_ModLst_Name.Text = CMain._T(TX.NAME)
        Me.LS_ModLst_Ver.Text = CMain._T(TX.VER)
        Me.LS_ModLst_Tip.Text = CMain._T(TX.TIP)

        Me.TX_Descr.Text = CMain._T(TX.NOSEL)

        Me.LB_Lang.Text = CMain._T(TX.LANG)
        Me.LB_Debug.Text = CMain._T(TX.DEBUGMODE)

        Me.GB_Alert.Text = CMain._T(TX.ALERTU)
        Me.GB_Inform.Text = CMain._T(TX.INFORMU)

        Me.RB_A_Prompt.Text = CMain._T(TX.USEPROMPT)
        Me.RB_A_Popup.Text = CMain._T(TX.USEPOPUP)
        Me.RB_I_Prompt.Text = CMain._T(TX.USEPROMPT)
        Me.RB_I_Popup.Text = CMain._T(TX.USEPOPUP)

        Me.bUpdater.Text = CMain._T(TX.UPDATE)
        Me.bUnInst.Text = CMain._T(TX.UNINSTAL)
        Me.CK_AutoRun.Text = CMain._T(TX.AUTORUNMSG)

        '/////////////////////////////////////////////////////
        Dim li As System.Windows.Forms.ListViewItem
        Dim sName As String = Nothing
        Dim sTip As String = Nothing
        Dim sVer As String = Nothing
        

        '// show each module

        CM_3DPoints.GetInfos(sName, sTip, sVer)
        li = Me.LS_ModLst.Items.Add(sName)
        li.SubItems.Add(sTip)
        li.SubItems.Add(sVer)
        If (CApp.mi_3DPoints IS Nothing) then
            li.Checked = False
        Else
            li.Checked = True
        End If
        li.Tag = MIDS.FSK_PT3D

        CM_Dims.GetInfos(sName, sTip, sVer)
        li = Me.LS_ModLst.Items.Add(sName)
        li.SubItems.Add(sTip)
        li.SubItems.Add(sVer)
        If (CApp.mi_Dims IS Nothing) then
            li.Checked = False
        Else
            li.Checked = True
        End If
        li.Tag = MIDS.DIMS

        CM_Grid.GetInfos(sName, sTip, sVer)
        li = Me.LS_ModLst.Items.Add(sName)
        li.SubItems.Add(sTip)
        li.SubItems.Add(sVer)
        If (CApp.mi_Grid IS Nothing) then
            li.Checked = False
        Else
            li.Checked = True
        End If
        li.Tag = MIDS.GRID

        CM_ImageDb.GetInfos(sName, sTip, sVer)
        li = Me.LS_ModLst.Items.Add(sName)
        li.SubItems.Add(sTip)
        li.SubItems.Add(sVer)
        If (CApp.mi_ImageDb IS Nothing) then
            li.Checked = False
        Else
            li.Checked = True
        End If
        li.Tag = MIDS.IMGDB

        CM_PolyArea.GetInfos(sName, sTip, sVer)
        li = Me.LS_ModLst.Items.Add(sName)
        li.SubItems.Add(sTip)
        li.SubItems.Add(sVer)
        If (CApp.mi_PolyArea IS Nothing) then
            li.Checked = False
        Else
            li.Checked = True
        End If
        li.Tag = MIDS.POLYA

        CM_Symbols.GetInfos(sName, sTip, sVer)
        li = Me.LS_ModLst.Items.Add(sName)
        li.SubItems.Add(sTip)
        li.SubItems.Add(sVer)
        If (CApp.mi_Symbols IS Nothing) then
            li.Checked = False
        Else
            li.Checked = True
        End If
        li.Tag = MIDS.SIMB

        CM_Table.GetInfos(sName, sTip, sVer)
        li = Me.LS_ModLst.Items.Add(sName)
        li.SubItems.Add(sTip)
        li.SubItems.Add(sVer)
        If (CApp.mi_Table Is Nothing) Then
            li.Checked = False
        Else
            li.Checked = True
        End If
        li.Tag = MIDS.TABLE


        CM_Survey1.GetInfos(sName, sTip, sVer)
        li = Me.LS_ModLst.Items.Add(sName)
        li.SubItems.Add(sTip)
        li.SubItems.Add(sVer)
        If (CApp.mi_Surv1 Is Nothing) Then
            li.Checked = False
        Else
            li.Checked = True
        End If
        li.Tag = MIDS.SURV1

        CM_Polyline.GetInfos(sName, sTip, sVer)
        li = Me.LS_ModLst.Items.Add(sName)
        li.SubItems.Add(sTip)
        li.SubItems.Add(sVer)
        If (CApp.mi_Polyline Is Nothing) Then
            li.Checked = False
        Else
            li.Checked = True
        End If
        li.Tag = MIDS.POLY



#If RO_SPECIFICS = True Then

        CM_RO_Tables.GetInfos(sName, sTip, sVer)
        li = Me.LS_ModLst.Items.Add(sName)
        li.SubItems.Add(sTip)
        li.SubItems.Add(sVer)
        If (CApp.mi_RoTables Is Nothing) Then
            li.Checked = False
        Else
            li.Checked = True
        End If
        li.Tag = MIDS.RO_TABLE

#End If


        Me.CB_Lang.Items.Add(CMain.sTxTbl_EN(TX.LANGNAME))
        Me.CB_Lang.Items.Add(CMain.sTxTbl_RO(TX.LANGNAME))
        Me.CB_Lang.SelectedIndex = CMain.eAppLang

        Me.CB_Debug.Items.Add(CMain.sTxTbl_EN(TX.NONE))
        Me.CB_Debug.Items.Add(CMain.sTxTbl_RO(TX.DBGPRINT))
        Me.CB_Debug.Items.Add(CMain.sTxTbl_EN(TX.LOG))
        Me.CB_Debug.Items.Add(CMain.sTxTbl_RO(TX.PROMPT))
        Me.CB_Debug.Items.Add(CMain.sTxTbl_RO(TX.LOGPROMPT))
        Me.CB_Debug.SelectedIndex = CMain.eAppDbg

        If CMain.bAlertType = CMain.ALERTTY.MSGB Then
            Me.RB_A_Popup.Checked = true
        Else
            Me.RB_A_Prompt.Checked = true
        End If
        If CMain.bInformType = CMain.INFORMTY.MSGB Then
            Me.RB_I_Popup.Checked = true
        Else
            Me.RB_I_Prompt.Checked = true
        End If

        '// are we auto-runned?
        If (CApp.regAppAddInKey Is Nothing) Then
            CK_AutoRun.Enabled = False
        Else
            Dim sRgs As String = CApp.regAppAddInKey.GetValue("LOADCTRLS", "16")
            If (sRgs = "16") Then
                CK_AutoRun.Checked = False
            Else
                CK_AutoRun.Checked = True
            End If
        End If




    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub LS_ModLst_SelectedIndexChanged( _
        ByVal sender As System.Object,  _
        ByVal e As System.EventArgs) _
        Handles LS_ModLst.SelectedIndexChanged

        If Me.LS_ModLst.SelectedItems.Count = 0 Then
            Me.TX_Descr.Text = CMain._T(TX.NOSEL)
            Return
        End If


        Me.TX_Descr.Text = _
        Capp.MLDescrByID( _
            DirectCast( _
                Me.LS_ModLst.SelectedItems(0).Tag, _
                MIDS))


    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub bUpdater_Click( _
        ByVal sender As System.Object,  _
        ByVal e As System.EventArgs) Handles bUpdater.Click

        Try
            '// enshure that the update folder exists
            If Not (system.IO.Directory.Exists(CApp.sAppPath & "Update")) Then
                system.IO.Directory.CreateDirectory(CApp.sAppPath & "Update")
            End If
            '// enshure that updater is loaded
            Dim acDoc As Autodesk.AutoCAD.ApplicationServices.Document = _
                Autodesk.AutoCAD.ApplicationServices.Application. _
                    DocumentManager.MdiActiveDocument()
            If (acDoc IsNot Nothing) Then
                acDoc.SendStringToExecute("FILEDIA 0" & vbCr, _
                                          True, False, False)
                acDoc.SendStringToExecute("NETLOAD " & """" & CApp.sAppPath & _
                                        "FSK_Updater.dll" & """" & vbCr, _
                                          True, False, False)
                acDoc.SendStringToExecute("FILEDIA 1" & vbCr, _
                                          True, False, False)
            Else
                CMain.AlertUser(TX.ERRNODOC)
            End If

            Me.DialogResult = System.Windows.Forms.DialogResult.OK
            Me.Close()
        Catch ex As System.Exception
            CMain.DebugException(ex)
        End Try
        GC.Collect()
        GC.WaitForPendingFinalizers()
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub bUnInst_Click( _
        ByVal sender As System.Object,  _
        ByVal e As System.EventArgs) _
        Handles bUnInst.Click

        Try
            Me.DialogResult = System.Windows.Forms.DialogResult.OK
            Me.Close()

            Dim udlg As New UnInstal
            Autodesk.AutoCAD.ApplicationServices. _
                Application.ShowModalDialog(udlg)

        Catch ex As System.Exception
            CMain.DebugException(ex)
        End Try
        GC.Collect()
        GC.WaitForPendingFinalizers()
    End Sub
    '// ===================================================================== '



End Class





'//  CLASS    =============================================================== '
'//
'//
'//
'//
'//  FUNCTIONS    ----------------------------------------------------------- '

'//  FUNCTIONS    =========================================================== '
'//
'//
'//
'//
'// ------------------------------------------------------------------------- '
'// ========================================================================= '
